module ThoughtsHelper
  def paint_stat(thought, method, options = {})
    options[:as] ||= method.to_s
    options[:plural] ||= options[:as].pluralize
    options[:class] ||= "stat "

    value = thought.send(method)

    options[:class] += " #{options[:zero_class]}"if options[:zero_class] and value == 0
    options[:class] += " #{options[:positive_class]}" if options[:positive_class] and value > 0
    noun = (value == 1 ? options[:as] : options[:plural])

    return "<div class=\"#{options[:class]}\"><span class=\"value\">#{value}</span> <span class=\"unit\">#{noun}</span></div>"
  end
  
def vote_up_for(votable_id, enabled = true)
  link_to_remote("+", :url => {:controller => 'thoughts', :action => 'vote', :id => votable_id, :vote_value => 1}, :html => {:id => "vote_up_t#{votable_id}",:class => "vote_up"})
  end

  def vote_down_for(votable_id, enabled = true)
    link_to_remote("-", :url => {:controller => 'thoughts', :action => 'vote', :id => votable_id, :vote_value => -1}, :html => {:id => "vote_down_t#{votable_id}", :class => "vote_down"})
  end

  def recant_vote_for(votable_id)
    vote = Vote.find(:first, :conditions => {:thought_id => votable_id})
    if vote.value == 1
      link_to_remote("+", :url => {:controller => 'thoughts', :action => 'vote', :id => votable_id, :vote_value => 0}, :html => {:id => "recant_vote_t#{votable_id}", :class => "vote_up selected"})
    elsif vote.value == -1
      link_to_remote("-", :url => {:controller => 'thoughts', :action => 'vote', :id => votable_id, :vote_value => 0}, :html => {:id => "recant_vote_t#{votable_id}", :class => "vote_down selected"})
    end
  end
  
end
